update SDK to call version directly#5145
update SDK to call version directly#5145codeboten wants to merge 7 commits intoopen-telemetry:mainfrom
Conversation
Removing the call to version in the resource to reduce the amount of libraries imported. ~17–27% memory reduction across all scenarios ~11–23% startup time reduction Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
| logger.exception( | ||
| "Failed to load resource detector '%s', skipping", | ||
| resource_detector, | ||
| extra_detector_names: Set[str] = { |
There was a problem hiding this comment.
The usage of set here introduces non-determinism in the ordering of resource detectors.
| if "*" in extra_detector_names: | ||
| # Expand wildcard to all registered detectors except "otel" (already added) | ||
| extra_detector_names = ( | ||
| set(entry_points(group="opentelemetry_resource_detector").names) # type: ignore[reportUnknownArgumentType] |
There was a problem hiding this comment.
Same here with the usage of set.
| # "otel" is always included and resolves to OTELResourceDetector (defined in | ||
| # this module), so we instantiate it directly to avoid an entry_points scan | ||
| # in the common case where no extra detectors are configured. | ||
| resource_detectors: List[ResourceDetector] = [OTELResourceDetector()] |
There was a problem hiding this comment.
Fyi, the OTELResourceDetector should be merged last, not first.
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
|
Thanks for the updates! One more small comment is that the previous behavior was to allow modifying the merge order of the "otel" resource detector by respecting its position in the resource detectors list if it is explicitly provided. This is a pretty fringe use-case, but I'd prefer to keep this behavior if possible. |
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
…to method Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
|
@herin049 i think i've addressed all your comments, please take a look |
| ) | ||
| ) | ||
|
|
||
| if "otel" not in detector_names: |
There was a problem hiding this comment.
Tiny suggestion, this is not needed if:
In [31]: list(dict.fromkeys([name.strip() for name in "a,c,otel,a,b".split(",") if name.strip()] + ["otel"]))
Out[31]: ['a', 'c', 'otel', 'b']
In [32]: list(dict.fromkeys([name.strip() for name in "a,c,a,b".split(",") if name.strip()] + ["otel"]))
Out[32]: ['a', 'c', 'b', 'otel']
| ) | ||
|
|
||
| if "*" in detector_names: | ||
| registered = sorted( |
There was a problem hiding this comment.
Does it make sense to sort them? Order should not be deterministic here in my opinion since the only criteria for ordeing is their name.
| if "*" in detector_names: | ||
| registered = sorted( | ||
| name | ||
| for name in entry_points( | ||
| group="opentelemetry_resource_detector" | ||
| ).names # type: ignore[reportUnknownArgumentType] | ||
| if name != "otel" | ||
| ) | ||
| existing = set(detector_names) - {"*"} | ||
| expansion = [n for n in registered if n not in existing] | ||
| idx = detector_names.index("*") | ||
| detector_names = ( | ||
| detector_names[:idx] + expansion + detector_names[idx + 1 :] | ||
| ) |
There was a problem hiding this comment.
| if "*" in detector_names: | |
| registered = sorted( | |
| name | |
| for name in entry_points( | |
| group="opentelemetry_resource_detector" | |
| ).names # type: ignore[reportUnknownArgumentType] | |
| if name != "otel" | |
| ) | |
| existing = set(detector_names) - {"*"} | |
| expansion = [n for n in registered if n not in existing] | |
| idx = detector_names.index("*") | |
| detector_names = ( | |
| detector_names[:idx] + expansion + detector_names[idx + 1 :] | |
| ) | |
| if "*" in detector_names: | |
| registered = set( | |
| name | |
| for name in entry_points( | |
| group="opentelemetry_resource_detector" | |
| ).names # type: ignore[reportUnknownArgumentType] | |
| if name != "otel" | |
| ) | |
| expansion = sorted(registered - set(detector_names)) | |
| idx = detector_names.index("*") | |
| detector_names = ( | |
| detector_names[:idx] + expansion + detector_names[idx + 1 :] | |
| ) |
Description
Removing the call to version in the resource to reduce the amount of libraries imported.
~17–27% memory reduction across all scenarios
~11–23% startup time reduction
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Contrib Repo Change?
Checklist: